Imports System.Windows.Forms

Public Class frmFind

    Public DataGrid As DataGridView

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        'search from current position
        Dim ColName As String = Me.cboColumnName.Text '.Replace(" ", "_")
        With DataGrid
            For r As Integer = .CurrentCell.RowIndex + 1 To .RowCount - 1
                If .Item(ColName, r).Value IsNot Nothing Then
                    Dim s As String = .Item(ColName, r).Value.ToString.ToUpper
                    If .Columns(ColName).ValueType Is GetType(Date) Then s = MyCDate(.Item(ColName, r).Value).ToString(MyDateTimeFormat)
                    If s Like Me.txtSearchString.Text.ToUpper Then
                        .CurrentCell = .Item(ColName, r)
                        Exit Sub
                    End If
                End If
                If MainForm IsNot Nothing AndAlso Not MainForm.WriteProgress(r, .RowCount - 1, "Searching...", ProgressBarStyle.Blocks, True) Then Exit For
            Next
            WarningMsgFmt("Search string '{0}' not found in column {1}", Me.txtSearchString.Text, Me.cboColumnName.Text)
        End With
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.Close()
    End Sub

    Private Sub frmFind_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        With DataGrid
            Me.cboColumnName.Items.Clear()
            For Each col As DataGridViewColumn In DataGrid.Columns
                Me.cboColumnName.Items.Add(col.Name)
            Next
        End With
        Me.cboColumnName.SelectedIndex = 0
    End Sub
End Class
